<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ES6---判断对象是否为{}</title>
</head>

<body>
    <script>
        let obj = {}
        // let obj = {name:'123'}

        //方法1：将obj对象转化为json字符串，再判断该字符串是否为"{}"
        function ff1(){
            alert(JSON.stringify(obj)==='{}')
        }

        //方法2：使用ES6的Object.keys()方法，返回值是对象中属性名组成的数组
        function ff2(){
            let keys = Object.keys(obj)
            if(keys.length){
                alert('对象不为{}')
            }else{
                alert('对象为{}')
            }
        }

        ff1()
    </script>
</body>

</html>